<?php
/**
 * @package LaravelBoot
 *
 * @internal
 *
 * @author mawenpei
 * @date 2019/4/2 20:54
 * @version
 */
namespace Modules\Admin\Main\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Advs;
use App\Models\Notice;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;

class NoticeController extends Controller
{
    public function search(Request $request)
    {
        return view('main::notice',$request->all());
    }

    public function apiSearch(Request $request)
    {
        $data = [];
        $data['total'] = Notice::query()->count();
        $data['items'] = Notice::query()->get();
        return success($data);
    }

    public function apiAdd(Request $request)
    {
        $input = $request->only(['content','redirect_type','redirect_to','url']);
        $cid = Notice::query()->insertGetId($input);
        if($cid) return success('添加成功');
    }

    public function apiUpdate(Request $request)
    {
        $cid = $request->input('id');
        $input = $request->only(['content','redirect_type','redirect_to','url']);
        if($cid) {
            Notice::query()->where('id',$cid)->update($input);
        }
        return success('更新成功');
    }

    public function apiDelete(Request $request)
    {
        $id = $request->input('id');
        if($id){
            Notice::query()->where('id',$id)->delete();
        }
        return success();
    }

    public function apiOptions(Request $request)
    {
        $data = [];
        $h5 = config('dialog.h5');
        $data['app_redirect_list'] = [
            ['label'=>'不跳转','value'=>''],
            ['label'=>'油卡套餐','value'=>'oilPay'],
            ['label'=>'油卡直充','value'=>'timelyPay'],
            ['label'=>'话费充值','value'=>'phoneBill'],
            ['label'=>'安全保障','value'=>'safePage'],
            ['label'=>'新人专享','value'=>'newPerson'],
            ['label'=>'邀请有礼','value'=>'share'],
        ];
        $data['h5_redirect_list'] = [
            ['label'=>'不跳转','value'=>''],
            ['label'=>'油卡套餐','value'=>$h5.'oilPay'],
            ['label'=>'油卡直充','value'=>$h5.'timelyPay'],
            ['label'=>'话费充值','value'=>$h5.'phoneBill'],
            ['label'=>'安全保障','value'=>$h5.'safePage'],
            ['label'=>'新人专享','value'=>$h5.'newPerson'],
            ['label'=>'邀请有礼','value'=>$h5.'share'],
        ];
        return success($data);
    }
}